//package com.applink.sell_proof.fragment;
//
//import java.util.ArrayList;
//
//import android.content.Context;
//import android.os.AsyncTask;
//import android.os.Bundle;
//import android.os.Handler;
//import android.os.Message;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.ListView;
//import android.widget.TextView;
//
//import com.actionbarsherlock.app.SherlockFragment;
//import com.applink.sell_proof.BasePagerActivity;
//import com.applink.sell_proof.EMarketing;
//import com.applink.sell_proof.R;
//import com.applink.sell_proof.adapter.RewardStatementConfigAdapter;
//import com.applink.sell_proof.api.DataHelper;
//import com.applink.sell_proof.database.table.RewardDBHelper;
//import com.applink.sell_proof.pojo.GenericObject;
//import com.applink.sell_proof.share.Parameter;
//import com.applink.sell_proof.utilXMLParser.ColumnSetting;
//import com.applink.sell_proof.utilXMLParser.DesignFormatParser;
//import com.applink.sell_proof.utilXMLParser.ObjPropInfo;
//import com.applink.sell_proof.utilXMLParser.ObjectFormatParser;
//
//public class NewRewardStatementConfigFragment extends SherlockFragment {
//	
//	protected ViewGroup mLayout;
//	private int mReferenceLoading = 2;
//	private View mHeaderReward;
//	private static final int SHOW_DATA = 0;
//	private RewardStatementConfigAdapter mAdapter;
//	private ListView listRewardStatement;
//	private TextView txtTotal;
//	private int total = 0;	
//	private Context mContext;
//	
//	@Override
//	public View onCreateView(LayoutInflater inflater, ViewGroup container,
//			Bundle savedInstanceState) {	
//		init(inflater,container);
//		setHasOptionsMenu(true);
//		((BasePagerActivity)getActivity()).showProgressDialog(R.id.reward_statement_container_loading);
//		
//		return mLayout;
//	}
//	
//	private class loadData extends AsyncTask<Void, Void, Integer>{
//
//		@Override
//		protected Integer doInBackground(Void... params) {
//			DataHelper.getInstance().getReward();
//			return 0;
//		}
//		
//		@Override
//		protected void onPostExecute(Integer result) {
//			mHandler.sendEmptyMessage(SHOW_DATA);
//			super.onPostExecute(result);
//		}		
//	}
//	
//	@Override
//	public void onActivityCreated(Bundle savedInstanceState) {
//		super.onActivityCreated(savedInstanceState);
//		//mContext = this;
//		new loadData().execute();
//	}
//	
//   private Handler mHandler = new Handler(new Handler.Callback() {
//		
//		@Override
//		public boolean handleMessage(Message msg) {
//			switch (msg.what) {
//			case SHOW_DATA:
//				((BasePagerActivity)getActivity()).hideProgressDialog(R.id.reward_statement_container_loading);
//				
//					/***
//				 	*if you want to add new information please follow below steps 
//			   			0. database - add more new columns data to wrap precisely
//			   			1. change contentData_Rewards.xml by add more properties in range (int, double, char)
//			   			2. change  List_Setting (rptrDesign_Rewards.xml) by add more columns
//			   			3. change xmlLayout file and copy it into asset folder.
//				 	*if you want to change existed by the order or remove some information, follow below steps
//			    		1. change  List_Setting (rptrDesign_Rewards.xml) by its order in asset folder
//			    		2. change xmlLayout file as well as its displaying order, then copy the file into asset folder
//				 	*/			
//					/***
//					this section is to parse properties setting of Object Reward based on contentData_Rewards.xml
//					an ObjPropInfo object is considered as an attribute of REAL OBJECT
//					 ***/
//					ArrayList<ObjPropInfo> objPropList = parseObjectProperty();
//			
//					/***
//			 		this section is to load data suitably from properties setting
//			 		from the collection of ObjPropInfo objects, we virtualize and wrap it into a real GenericObject Instance
//					genericObjectList contains all GenericObject records fetched from SQLite
//					 ***/
//					ArrayList<GenericObject> genericObjectList = loadDataFromObjectProperty(objPropList);
//					
//					if(genericObjectList.size() == 0){ //this means there is no data
//						return false;
//					}
//					
//					/***
//				  	this section is to parse List View columns setting based on rptrDesign_Rewards.xml
//					 ***/
//					ArrayList<ColumnSetting> columnSettingList = parseColumnSetting();
//
//					//Constant.dataReward = RewardDBHelper.getAllReward();
//										
//					if(mAdapter == null){
//						//for(int i = 0;i< Constant.dataReward.size(); i++){
//						//	total = total + Constant.dataReward.get(i).getRewardAmount();
//						//}
//						//mAdapter = new RewardStatementConfigAdapter(EMarketing.getInstance().getApplicationContext(),Constant.dataReward,columnSettingList);
//						mAdapter = new RewardStatementConfigAdapter();
//						//mAdapter = new RewardStatementConfigAdapter(EMarketing.getInstance().getApplicationContext(),genericObjectList,columnSettingList);
//						listRewardStatement.setAdapter(mAdapter);
//						//txtTotal.setText(String.valueOf(total));
//					}else{
//						mAdapter.notifyDataSetChanged();
//					}
//				break;
//
//			default:
//				break;
//			}
//			return false;
//		}
//	});
//	private void init(LayoutInflater inflater,ViewGroup container){
//		if(mLayout == null){
//			mLayout = (ViewGroup) inflater.inflate(R.layout.reward_statement, null, false);
//		}
//		if(listRewardStatement == null){
//			listRewardStatement = (ListView) mLayout.findViewById(R.id.list_reward_statement);
//		}
//		mHeaderReward = inflater.inflate(R.layout.header_reward_claim, null);
//		if(txtTotal == null){
//			txtTotal = (TextView) mHeaderReward.findViewById(R.id.totalearned); 
//		}
//		listRewardStatement.addHeaderView(mHeaderReward);
//		listRewardStatement.setVisibility(View.VISIBLE);
//	}
//	
//	private ArrayList<ColumnSetting> parseColumnSetting() {
//
//		ArrayList<ColumnSetting> columnSettingList = new ArrayList<ColumnSetting> ();
//		columnSettingList  = DesignFormatParser.ParserIntoColumnSetting(EMarketing.getInstance().getApplicationContext(),"rptrDesign_Rewards.xml",Parameter.COL_TAGNAME);		
//		return columnSettingList;
//	}
//	
//	private ArrayList<ObjPropInfo> parseObjectProperty() {
//		ArrayList<ObjPropInfo> objPropList = new ArrayList<ObjPropInfo> ();
//		// an ObjPropInfo object is considered as an attribute of REAL OBJECT
//		//here we select all PropInfo tag of the object which has ->  <om_id>Rewards</om_id> or <om_id>OutletStaff</om_id> 
//		objPropList  = ObjectFormatParser.ParserIntoObjProp(EMarketing.getInstance().getApplicationContext(),"contentData_Rewards.xml",Parameter.OBJ_PROP_TAGNAME,"Rewards");	
//
//		return objPropList ;
//	}
//	
//	private ArrayList<GenericObject> loadDataFromObjectProperty(ArrayList<ObjPropInfo> objPropList) {
//		//we then load data from SQLite and wrap the data into generic Object
//		ArrayList<GenericObject> genericObjectList = new ArrayList<GenericObject>();
//		genericObjectList =	RewardDBHelper.getObjectBasedConfig(objPropList);
//	
//		return genericObjectList; 
//	}
//}
